package com.xc.mail.controller;

import com.xc.mail.pojo.Employee;
import com.xc.mail.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName EmployeeController.java
 * @Description TODO
 * @createTime 2021年04月23日 16:00:00
 */
@RestController
public class EmployeeController {

        @Autowired
        private EmployeeService employeeService;

        @GetMapping(value = "/getEmpById")
        public Employee getEmpById(@RequestParam(value = "id") Integer id){
            return employeeService.getEmpById(id);
        }

        @GetMapping(value = "/getEmp")
        public Employee getEmp(@RequestParam(value = "id") Integer id, @RequestParam(value = "gender",required = false) String gender){
                Employee emp = employeeService.getEmp(id,gender);
                System.out.println(id+gender);
                System.out.println(emp.toString());
                return emp;
        }



        @PostMapping(value = "/addEmp")
        public String addEmp(Employee employee){
                int i = employeeService.addEmp(employee);
                System.out.println(employee.getId());
                if(i>0){
                     return "添加成功";
                }else{
                        return "添加失败";
                }
        }


        @RequestMapping(value = "/updateEmp",method = RequestMethod.POST)
        public  String update(Employee employee){
                int i = employeeService.updateEmp(employee);
                if(i>0){
                      return "修改成功";
                }else{
                        return "修改失败";
                }
        }

        @GetMapping(value = "/delEmp")
        public void delEmp(@RequestParam("id") Integer id){
                employeeService.delEmp(id);
        }

}
